<template>
  <div>
    用户名:<input type="text" v-model="loginForm.username" placeholder="请输入用户名"/>
    <br><br>
    密码： <input type="password" v-model="loginForm.password" placeholder="请输入密码"/>
    <br><br>
    再次输入密码： <input type="checkpassword" v-model="loginForm.checkpassword" placeholder="请再次输入密码"/>
    <br><br>
    <button v-on:click="register">注册</button>
  </div>
</template>

<script>

export default {
  name: 'Register',
  data () {
    return {
      loginForm: {
        username: '',
        password: '',
        checkpassword: ''
      },
      responseResult: []
    }
  },
  methods: {
    register () {
      var username = this.loginForm.username
      var password = this.loginForm.password
      var checkpassword = this.loginForm.checkpassword
      this.$axios.post(
          "/user/register?username="+username+"&password="+password+"&checkpassword="+checkpassword).then(successResponse => {
        if (successResponse.data.code === 200) {
          alert("注册成功！")
          this.$router.replace({path: '/login'})
        } else{
          alert(successResponse.data.msg)
        }
      })
          .catch(failResponse => {
          })
    }
  }
}
</script>

